from graphics import *
import random

def window(title):
    begin()
    reset_viewport()
    set_fill_style(FILL_SOLID)
    set_line_style(1)
    clear(C_BLACK)
    draw_text(viewport().width/2, 2, title, ha = A_CENTER, color = C_WHITE)
    draw_text(width()/2, height() - 2, 'Esc aborts or press a key...', ha = A_CENTER, va = A_BOTTOM, color = C_WHITE)
    th,tw = text_size("XXXX")

    set_viewport(viewport().border(th + 4, 10))
    draw_rect(0, 0, viewport().width-1, viewport().height-1, fill=False)
    set_viewport(viewport().border(1))
    end()
    print(title+"...")

def wait():
    key = read_key()
    if key.keysym == gtk.keysyms.Escape:
        raise Close()


def rand(n):
    return random.randint(0, n-1)

def rand_color():
    return COLORS[rand(len(COLORS))]
